Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker resource detector #931

Merged
merged 33 commits into from
Mar 17, 2022
Merged

feat: add docker resource detector #931

merged 33 commits into from
Mar 17, 2022

Conversation

abhee11
Copy link
Contributor

@abhee11 abhee11 commented Mar 3, 2022

Which problem is this PR solving?

Short description of the changes

  • adding a new detector for docker container id cgroupov1 only

Checklist

  • Ran npm run test-all-versions for the edited package(s) on the latest commit if applicable.

@abhee11 abhee11 requested a review from a team March 3, 2022 22:15
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 3, 2022

CLA Signed

The committers are authorized under a signed CLA.

@abhee11 abhee11 closed this Mar 3, 2022
@abhee11 abhee11 reopened this Mar 3, 2022
@@ -0,0 +1,58 @@
{
"name": "@opentelemetry/resource-detector-docker",
"version": "1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we can release directly as 1.0 ? waiting for other maintainers input on this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would definitely prefer to start with 0.1.0

Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the detector itself looks good to me, you'll need to fix the CLA though

@codecov
Copy link

codecov bot commented Mar 5, 2022

Codecov Report

Merging #931 (2c6ddc0) into main (acd6a6f) will decrease coverage by 0.08%.
The diff coverage is 93.54%.

❗ Current head 2c6ddc0 differs from pull request most recent head a496b1c. Consider uploading reports for the commit a496b1c to get more accurate results

@@            Coverage Diff             @@
##             main     #931      +/-   ##
==========================================
- Coverage   95.91%   95.82%   -0.09%     
==========================================
  Files          13       15       +2     
  Lines         856      887      +31     
  Branches      178      182       +4     
==========================================
+ Hits          821      850      +29     
- Misses         35       37       +2     
Impacted Files Coverage Δ
...tor-docker/src/detectors/DockerCGroupV1Detector.ts 93.33% <93.33%> (ø)
...ry-resource-detector-docker/src/detectors/index.ts 100.00% <100.00%> (ø)

@abhee11 abhee11 closed this Mar 7, 2022
@abhee11 abhee11 reopened this Mar 7, 2022
Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyladan dyladan changed the title Add docker cgroup containerid feat: add docker resource detector Mar 7, 2022
@dyladan
Copy link
Member

dyladan commented Mar 7, 2022

you'll also need to add there: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.release-please-manifest.json so it can be automatically published

I think this isn't true anymore with release-please v3

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 7, 2022

Just cleaning out some lint issues - waiting for jobs to run - @dyladan @vmarchaud
I updated the .release-please-manifest.json as per the comment - let me know if you like me to revert it.

I appreciate the review on this - thank you

Copy link
Member

@rauno56 rauno56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job! Thanks.

As Daniel mentioned, editing release-please-manifest is not required anymore. Please revert the change.

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 11, 2022

@Flarna As per comments above - I believe we dont need that anymore ?
@dyladan Please review changes and my comments for \r and the READ.ME change - let me know what you think

@Flarna
Copy link
Member

Flarna commented Mar 11, 2022

@abhee11 no need anymore to touch .release-please-manifest.json but still needed to add a new package in release-please-config.json.

See #938 which shows that this is still needed.

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 11, 2022

@Flarna my bad - pushed - thanks

[SemanticResourceAttributes.CONTAINER_ID]: containerId || '',
});
} catch (e) {
diag.warn('Process is not running on a supported docker version', e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be warn? I think it's valid. User should be able to install a resource detector and have it working only when relevant IMO.
I suggest differentiating between 2 cases:

  1. "no docker" case which should report info and not report the error in the message
  2. some unexpected exception was thrown - error and includ the error in the message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So - the reason for this is - if you are installing DockerResourceV1Detector - that would mean - you are adding this dependency assuming you have v1 version running - hence the warning !

As this dependency would be of no use if it did get them the container id - hence we need to warn them that they need have a diff docker version running.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on the other thread

Comment on lines 64 to 68
if (e instanceof Error) {
errorMessage = e.message;
diag.warn(
`Docker CGROUP V1 Detector failed to read container ID: ${errorMessage}`
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous comment. If the file is missing, I suggest to not log warn since it's valid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to let the user know that their dockerV1Detector is not doing as they hoped. I am wondering if their a another way - do you have any suggestions ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if including a resource detector means that the user is expecting that resource to be present.

2 Examples:

  1. If the user installs an aws detector and then runs his service locally, I wouldn't expect any warnings to be printed to log as this is completely valid and the message will be confusing. Maybe the service is running inside a docker in production but not in other environments.
  2. If someone creates a distribution of OpenTelemetry and includes many detectors, the expectation (as far as I am aware) is that only the relevant detectors will be applied. Detectors that are not relevant should be silently ignored. This is the way instrumentations are handled: if someone installs the @opentelemetry/auto-instrumentations-node package with all instrumentations, and then his app does not require redis package, then instrumentation-redis will just not load with no warning to diag channel

I think emitting it as info makes more sense, something like: "Docker CGROUP V1 Detector did not identify running inside a docker container, no docker attributes will be added to resource".

This is for the case that the file does not exist. If the file exists but exception is thrown for any other reason, I would expect an error with message that includes the errorMessage.

This is my take on it, but I'm open for other opinions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoting from the DiagLogger interface:

  /**
   * Log a warning scenario to inform the developer of an issues that should be investigated.
   * The requested operation may or may not have succeeded or completed.
   */
  warn: DiagLogFunction;

I think when the file is missing it doesn't mean that the developer should investigate anything but only be informed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very helpful - thank you for taking the time and helping me out with this. I appreciate it.
Addressed.

readStub = sinon
.stub(DockerCGroupV1Detector, 'readFileAsync' as any)
.onSecondCall()
.rejects(errorMsg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation to return an object and not directly an Error?
I did not check but guess the fs functions returns an Error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

motivation is to keep it same as implementation where we are return an error obj.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstand you, but the test uses:

      const errorMsg = {
        fileNotFoundError: new Error('cannot file in the path}'),
      };

And it will not return an error, but an object with one key named fileNotFoundError which is an Error.
Is it consistent with what fs returns on err?
I would expect it to be something like:

.rejects(new Error('foo bar'));

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 14, 2022

Hello @blumamir
Thank you for the comments - I have updated the PR as per review comments.
I am still not sure about the diag.warn - but i am open to suggestions.

});

describe('Supported docker - Container ID ', () => {
it('should return a emoty resource - docker cgroup v1 detector', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: emoty -> empty :)

readStub = sinon
.stub(DockerCGroupV1Detector, 'readFileAsync' as any)
.onSecondCall()
.rejects(errorMsg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstand you, but the test uses:

      const errorMsg = {
        fileNotFoundError: new Error('cannot file in the path}'),
      };

And it will not return an error, but an object with one key named fileNotFoundError which is an Error.
Is it consistent with what fs returns on err?
I would expect it to be something like:

.rejects(new Error('foo bar'));

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 14, 2022

@blumamir I have addressed your comments and pushed the changes. Let me know if there is anything else.

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 16, 2022

@blumamir @dyladan Let me know if there is anything more I need to refactor - I have made the proposed changes

Copy link
Member

@blumamir blumamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. thanks for the patient and for addressing everything

@abhee11
Copy link
Contributor Author

abhee11 commented Mar 17, 2022

@blumamir Thank you, feel free to merge.

@rauno56
Copy link
Member

rauno56 commented Mar 17, 2022

Thanks for the contribution, @abhee11(first one, I believe), 🎉, and everyone for the thorough feedback.

@rauno56 rauno56 merged commit 4e31b3c into open-telemetry:main Mar 17, 2022
@dyladan dyladan mentioned this pull request Mar 17, 2022
@dyladan dyladan mentioned this pull request May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants